package com.nopay.dxdwphone.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.nopay.dxdwphone.R;

public class DialogWaitCallTransferSetting extends Dialog {

    public DialogWaitCallTransferSetting(@NonNull Activity context) {
        super(context, R.style.MyDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_wait_call_transfer_setting);
        setCancelable(false);
    }

    public void show(int time) {
        super.show();
        TextView tvCountDown = findViewById(R.id.tv_count_down);
        tvCountDown.setText("设置呼叫转移中" + time + "秒...");

        CountDownTimer timer = new CountDownTimer(time * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                tvCountDown.setText("设置呼叫转移中" + (millisUntilFinished / 1000) + "秒...");
            }

            @Override
            public void onFinish() {
                if(onWaitFinishListener != null) onWaitFinishListener.onWaitFinish();

                dismiss();
            }
        };
        timer.start();
    }

    private OnWaitFinishListener onWaitFinishListener;

    public DialogWaitCallTransferSetting setOnWaitFinishListener(OnWaitFinishListener onWaitFinishListener) {
        this.onWaitFinishListener = onWaitFinishListener;
        return this;
    }

    public interface OnWaitFinishListener {

        void onWaitFinish();
    }
}
